﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace HAOest.Forms.Buttons
{
    /// <summary>
    /// 简单按钮的抽象类
    /// </summary>
    public  partial class SimpleButton : UserControl
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public SimpleButton()
        {
            InitializeComponent();
        }

        private Image buttonImage;              //按钮图片
        private Color backColor;                //按钮背景颜色
        private Image mouseEnterButtonImage;    //鼠标经过时按钮图片
        private Color mouseEnterBackColor;      //鼠标经过时按钮背景颜色
        private Image chosenButtonImage;        //选中时按钮图片
        private Color chosenBackColor;          //选中时按钮背景颜色

        #region 属性
        /// <summary>
        /// 按钮图片
        /// </summary>
        [Browsable(true)]
        [Description("按钮图片")]
        [Category("外观")]
        public Image ButtonImage
        {
            get
            {
                return buttonImage;
            }
            set
            {
                buttonImage = value;
                ButtonPictureBox.Image = buttonImage;
            }
        }

        /// <summary>
        /// 按钮背景颜色
        /// </summary>
        [Browsable(true)]
        [Description("按钮背景颜色")]
        [Category("外观")]
        public override Color BackColor
        {
            get
            {
                return backColor;
            }
            set
            {
                backColor = value;
                ButtonPictureBox.BackColor = backColor;
            }
        }

        /// <summary>
        /// 鼠标经过时按钮图片
        /// </summary>
        [Browsable(true)]
        [Description("鼠标经过按钮图片")]
        [Category("外观")]
        public Image MouseEnterButtonImage
        {
            get
            {
                return mouseEnterButtonImage;
            }
            set
            {
                mouseEnterButtonImage = value;
            }
        }

        /// <summary>
        /// 鼠标经过时按钮背景颜色
        /// </summary>
        [Browsable(true)]
        [Description("鼠标经过时按钮背景颜色")]
        [Category("外观")]
        public Color MouseEnterBackColor
        {
            get
            {
                return mouseEnterBackColor;
            }
            set
            {
                mouseEnterBackColor = value;
            }
        }
        #endregion

        private void SimpleButton_MouseEnter(object sender, EventArgs e)
        {
            ButtonPictureBox.Image = mouseEnterButtonImage;
            ButtonPictureBox.BackColor = mouseEnterBackColor;
        }

        private void SimpleButton_MouseLeave(object sender, EventArgs e)
        {
            ButtonPictureBox.Image = buttonImage;
            ButtonPictureBox.BackColor = backColor;
        }

        /// <summary>
        /// 窗体动画
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="dwTime"></param>
        /// <param name="dwFlags"></param>
        /// <returns></returns>
        [System.Runtime.InteropServices.DllImport("user32")]
        public static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
    }
}
